package com.gzck.gzck_verson2.controller;


import cn.dev33.satoken.util.SaResult;
import com.gzck.gzck_verson2.pojo.GSensorInfo;
import com.gzck.gzck_verson2.pojo.vo.AddSensorVO;
import com.gzck.gzck_verson2.service.IGSensorInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 传感器信息/设备信息 前端控制器
 * </p>
 *
 * @author 任永辉
 * @since 2024-01-27
 */
@RestController
@RequestMapping("/g-sensor-info")
public class GSensorInfoController {

    @Autowired
    private IGSensorInfoService sensorInfoService;

    // 添加传感器信息
    @PostMapping("/add")
    public SaResult addSensorInfo(@RequestBody AddSensorVO addSensorVO) {
        return sensorInfoService.saveSensorInfo(addSensorVO);
    }


    // 删除传感器信息
    @DeleteMapping("/delete/{id}")
    public boolean deleteSensorInfo(@PathVariable Long id) {
        return sensorInfoService.removeById(id);
    }

    // 更新传感器信息
    @PutMapping("/update")
    public boolean updateSensorInfo(@RequestBody GSensorInfo sensorInfo) {
        return sensorInfoService.updateById(sensorInfo);
    }

    // 查询单个传感器信息
    @GetMapping("/{id}")
    public GSensorInfo getSensorInfo(@PathVariable Long id) {
        return sensorInfoService.getById(id);
    }

    // 查询所有传感器信息
    @GetMapping("/all")
    public List<GSensorInfo> getAllSensorInfos() {
        return sensorInfoService.list();
    }
}
